package utils;

import java.sql.Timestamp;
import java.util.List;

import dbhelper.Bids;
import dbhelper.Items;
import entities.Bid;

public class BidsHelper {

	/**
	 * posts the bid
	 * @param bid
	 * @return the new current bit amount of that item 
	 */
	public static double postBid(Bid bid){
		if(bid == null || bid.getMoney() < 0 || bid.getItemID() < 0 || 
				!Items.isForSaleItemStringQuery(bid.getItemID()) || bid.getUserID() < 0 ||
				bid.getUserID() == Items.getSellerID(bid.getItemID()))
			return -1;
		return (Bids.placeNewBid(bid)) ? Items.getCurrentBid(bid.getItemID()) : -1;
	}
	
	/**
	 * 
	 * @param userID
	 * @param pageNumber
	 * @param startFrom
	 * @return the bids of the user (null if the userID is invalid)
	 */
	public static List<Bid> getBids(long userID,int pageNumber,Timestamp startFrom){
		pageNumber = (pageNumber < 0) ? 0 : pageNumber;
		return (userID >= 0) ? Bids.getBids(userID, pageNumber, startFrom) : null;
	}
}
